package srm518;

public class LargestSubsequence {
    public String getLargest(String s) {
        StringBuilder sb = new StringBuilder();
        int index = 0;
        while (index < s.length()) {
            for (int i = index+1; i < s.length(); i++) {
                if (s.charAt(i) > s.charAt(index)) {
                    index = i;
                }
            }
            sb.append(s.charAt(index++));
        }
        return sb.toString();
    }

    // BEGIN KAWIGIEDIT TESTING
    // Generated by KawigiEdit 2.1.4 (beta) modified by pivanof
    private static boolean KawigiEdit_RunTest(int testNum, String p0, boolean hasAnswer, String p1) {
        System.out.print("Test " + testNum + ": [" + "\"" + p0 + "\"");
        System.out.println("]");
        LargestSubsequence obj;
        String answer;
        obj = new LargestSubsequence();
        long startTime = System.currentTimeMillis();
        answer = obj.getLargest(p0);
        long endTime = System.currentTimeMillis();
        boolean res;
        res = true;
        System.out.println("Time: " + (endTime - startTime) / 1000.0 + " seconds");
        if (hasAnswer) {
            System.out.println("Desired answer:");
            System.out.println("\t" + "\"" + p1 + "\"");
        }
        System.out.println("Your answer:");
        System.out.println("\t" + "\"" + answer + "\"");
        if (hasAnswer) {
            res = answer.equals(p1);
        }
        if (!res) {
            System.out.println("DOESN'T MATCH!!!!");
        } else if ((endTime - startTime) / 1000.0 >= 2) {
            System.out.println("FAIL the timeout");
            res = false;
        } else if (hasAnswer) {
            System.out.println("Match :-)");
        } else {
            System.out.println("OK, but is it right?");
        }
        System.out.println("");
        return res;
    }

    public static void main(String[] args) {
        boolean all_right;
        all_right = true;

        String p0;
        String p1;

        // ----- test 0 -----
        p0 = "test";
        p1 = "tt";
        all_right = KawigiEdit_RunTest(0, p0, true, p1) && all_right;
        // ------------------

        // ----- test 1 -----
        p0 = "a";
        p1 = "a";
        all_right = KawigiEdit_RunTest(1, p0, true, p1) && all_right;
        // ------------------

        // ----- test 2 -----
        p0 = "example";
        p1 = "xple";
        all_right = KawigiEdit_RunTest(2, p0, true, p1) && all_right;
        // ------------------

        // ----- test 3 -----
        p0 = "aquickbrownfoxjumpsoverthelazydog";
        p1 = "zyog";
        all_right = KawigiEdit_RunTest(3, p0, true, p1) && all_right;
        // ------------------

// ----- test 3 -----
        p0 = "abzdryfdaxerioz";
        p1 = "zz";
        all_right = KawigiEdit_RunTest(3, p0, true, p1) && all_right;
        // ------------------

        if (all_right) {
            System.out.println("You're a stud (at least on the example cases)!");
        } else {
            System.out.println("Some of the test cases had errors.");
        }
    }
    // END KAWIGIEDIT TESTING
}
//Powered by KawigiEdit 2.1.4 (beta) modified by pivanof!
